package lg.minecraft.plugin.cobblemoncore.config.mapping;

import com.cobblemon.mod.common.api.abilities.Abilities;
import com.cobblemon.mod.common.api.abilities.AbilityTemplate;
import lg.minecraft.plugin.cobblemoncore.LGCobblemonCore;
import lg.minecraft.plugin.cobblemoncore.util.LocalizedName;
import lombok.Getter;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class AbilityMapping extends AbstractMapping<AbilityTemplate> {

    public AbilityMapping() {
        super(LGCobblemonCore.getInstance(), "ability.yml", LGCobblemonCore.getMappingDirectory().getPath());
    }

    @Override
    protected boolean isUseLocalFile() {
        return LGCobblemonCore.getMainConfig().isAbility();
    }

    @Override
    protected void loadFromDynamicSource() {
        for (AbilityTemplate template : Abilities.INSTANCE.all()) {
            String displayName = LocalizedName.getAbilityName(template);
            set(template.getName(), displayName);
            mapping.put(displayName, template);
            reverse.put(template, displayName);
        }
    }

    @Override
    protected void loadFromLocalFile() {
        for (String key : getKeys(false)) {
            String value = getString(key);
            AbilityTemplate template = Abilities.INSTANCE.get(key);
            if (template == null) {
                getPlugin().getLogger().warning("Ability " + key + " not found!");
                continue;
            }
            mapping.put(value, template);
            reverse.put(template, value);
        }
    }

}
